/*!
 * author fdf
 * date 2015/07/1
 * description 对easyui中combogrid下拉表格框组件重构，实现分页和数据模糊搜索
 * mark 在火狐下输入中文那一刻不会触发onchange方法... 建议输完中文后多按一下空格键~~
 */
function initByFocus(temp) {
    var a_dom = temp.prev().children();
    initSelect(a_dom, 0);
}

function initByInputId(id) {
    var obj = $("#" + id);
    initByInputObject(obj);
}
function initByInputObject(obj) {
    var aObj = obj.prev().children().children();
    initSelect(aObj, 1);
}

//页面下拉框表格数据对于的映射
// var tableCover = {
// "co_hggqdm": export_port_dy,   //申报地海关
// "co_bgdlx": declaretiontypeby,  //报关单类型
// "co_hgbzzl": goodspackagetypeby,  //包装种类
// "hg_co_jzx": containerSpecification_by //集装箱规格

// "hg_co_bz": goodsCurrencyMode_dys,  //币制
// "co_hgzmf": exemptionof,        //征免
// "hg_co_ysgj": modeoftransport  //运输的方式
// };
//初始化
function initSelect(temp, isHidenPanel, ishasPage) {
    var reshowValue = temp.parent().next().val();
    var grf = temp.parent().parent();
    var obj = grf.next();
    if (obj.attr("isLock") && obj.attr("isLock") == "lock") {
        return;
    }
    ignoreBeforeunload();
    grf.remove();
    obj.show();
    var keyId = obj.attr("keyId");
    var valueId = obj.attr("valueId");
    var theCode = obj.attr("theCode");
    var codeId = obj.attr("codeId");
    var theKey = obj.attr("theKey");
    var theValue = obj.attr("theValue");
    var table = obj.attr("selectData");
    var secondTable = obj.attr("seondeData");
    var secondSelect = obj.attr("secondSelect");
    var domWidth = obj.attr("width");
    var notClearIfNotExist = obj.attr("notClearIfNotExist");
    var url = "";
    obj.attr("isInit", "1");
    if (table) {
        if (tableCover[table]) {
            url = tableCover[table];
        } else {
            url = '/order-dropdown/gqdm?table=' + table + "&theKey=" + theKey;
        }
    } else {
        //url = 'baseData_loadSecondData.do';
        var firstSel = $("input[childSelect=" + secondSelect + "]")[0];
        if (firstSel && (!$(firstSel).attr("hasInit") || $(firstSel).attr("hasInit") != "0")) {
            var property = {};
            var firstDOM = $(firstSel);
            property.firstValue = firstDOM.val();
            property.firstTable = firstDOM.attr("selectData");
            property.firstTheValue = firstDOM.attr("theValue");
            property.filterValue = obj.attr("filterValue");
            property.filterColumn = obj.attr("filterColumn");
            property.secondTheValue = obj.attr("theValue");
            property.secondTheKey = obj.attr("theKey");
            property.secondTable = obj.attr("seondeData");

            url = "baseData_loadSecondData.do?firstValue=" + property.firstValue + "&firstTable=" +
                  property.firstTable + "&firstTheValue=" + property.firstTheValue + "&filterValue="
                  +
                  property.filterValue + "&filterColumn=" + property.filterColumn
                  + "&secondTheValue=" +
                  property.secondTheValue + "&secondTheKey=" + property.secondTheKey
                  + "&secondTable=" +
                  property.secondTable;
        }
    }
    var combogridConfig = {
        "columns": [[
            {"field": theKey, "width": '220'}
        ]],
        "keyId": keyId,
        "textField": theKey, //显示的字段
        "valueId": valueId,
        "idField": theValue, //值字段
        "codeId": codeId,
        "codeField": theCode,
        "panelHeight": 210,
        "panelWidth": 220,
        "showHeader": false,
        "notClearIfNotExist": notClearIfNotExist,
        "striped": true,
        "editable": true,
        "fitColumns": false,//提高效率？？？
        "fit": false,//自动大小
        // "pagination": true,//是否分页
        "pagination": ishasPage == null ? true : false,//是否分页

        "pageSize": 7,
        "pageList": [7],//可以设置每页记录条数的列表
        "pageNumber": 1,
        "rownumbers": false,//序号
        "collapsible": false,//是否可折叠的
        loadFilter: loadDataFilter,
        keyHandler: {
            up: function () {//【向上键】押下处理
                //取得选中行
                var selected = obj.combogrid('grid').datagrid('getSelected');
                if (selected) {
                    //取得选中行的rowIndex
                    var index = obj.combogrid('grid').datagrid('getRowIndex',
                                                               selected);
                    //向上移动到第一行为止
                    if (index > 0) {
                        obj.combogrid('grid').datagrid('selectRow', index - 1);
                    }
                } else {
                    var rows = obj.combogrid('grid').datagrid('getRows');
                    obj.combogrid('grid').datagrid('selectRow', rows.length - 1);
                }
            },
            down: function () {//【向下键】押下处理
                //取得选中行
                var selected = obj.combogrid('grid').datagrid('getSelected');
                if (selected) {
                    //取得选中行的rowIndex
                    var index = obj.combogrid('grid').datagrid('getRowIndex',
                                                               selected);
                    //向下移动到当页最后一行为止
                    if (index < obj.combogrid('grid').datagrid('getData').rows.length
                                - 1) {
                        obj.combogrid('grid').datagrid('selectRow', index + 1);
                    }
                } else {
                    obj.combogrid('grid').datagrid('selectRow', 0);
                }
            },
            enter: function () {//【回车键】押下处理
                obj.combogrid("hidePanel");
                EnterTransTab($(this));
            },
            query: function (keyword) {//【动态搜索】处理
                obj.combogrid("setValue", keyword);
                obj.combogrid("setText", keyword);
                if (table) {
                    obj.combogrid("grid").datagrid('load', {'keyword': keyword});
                } else {
                    var firstSel = $("input[childSelect=" + secondSelect + "]")[0];
                    loadSecondData($(firstSel), obj, keyword);
                }
                //obj.combogrid('grid').datagrid('getPager').pagination("select",1);
            }
        },
        onHidePanel: function () {
            var selected = obj.combogrid('grid').datagrid("getSelected");
            var checkValue = obj.combogrid("getText");

            if (selected) {
                //if(obj.combogrid('getValue') != selected[theValue]) {
                if (obj.combogrid('getValue') == obj.combogrid('getText')) {
                    obj.combogrid('setValue', selected[theValue]);
                    obj.combogrid('setText', selected[theKey]);
                    setKeyIdAndValuIdForValue(keyId, valueId, codeId,
                                              selected[theKey], selected[theValue],
                                              selected[theCode]);
                    //清除二级下拉框的值
                    var childSelect = obj.attr("childSelect");
                    if (childSelect) {
                        $("input[secondSelect=" + childSelect + "]").each(
                            function () {
                                var secondSEL = $(this);
                                var secondClass = secondSEL.attr("class");
                                if (secondClass && secondClass.indexOf("combogrid-f")
                                                   > -1) {
                                    secondSEL.combogrid("clear");
                                } else {
                                    secondSEL.prev().children().val("");
                                    secondSEL.next().val("");
                                    secondSEL.val("");
                                }
                            });
                    }
                } else {
                    //按回车键时，显示值和真实值不一致，自动填充
                    obj.combogrid("setValue", selected.SHOWNAME);
                }
                //默认选中第一行后，后面的判断就不再运行了
            } else {
                obj.combogrid("setValue", "");
                obj.combogrid("textbox").next().val("");
            }
            // else if (checkValue) {
            //     /**/
            //     if (notClearIfNotExist) {
            //         $("#" + keyId).attr("value", checkValue);
            //         var ids = [valueId, keyId, codeId];
            //         validate(ids);
            //         return;
            //     }
            //
            //     /*
            //      var firstRow = obj.combogrid('grid').datagrid("getData").rows[0];
            //      if(firstRow) {
            //      if(obj.combogrid('getValue') != firstRow[theValue]) {
            //      obj.combogrid('setValue', firstRow[theValue]);
            //      obj.combogrid('setText', firstRow[theKey]);
            //      //清除二级下拉框的值
            //      var childSelect = obj.attr("childSelect");
            //      if(childSelect) {
            //      $("input[secondSelect="+childSelect+"]").each(function() {
            //      var secondSEL = $(this);
            //      var secondClass = secondSEL.attr("class");
            //      if(secondClass && secondClass.indexOf("combogrid-f")>-1) {
            //      secondSEL.combogrid("clear");
            //      }
            //      });
            //      }
            //      }
            //      return;
            //      }
            //      */
            //
            //     var checkTable = "";
            //     if (table) {
            //         checkTable = table;
            //     } else {
            //         checkTable = secondTable;
            //     }
            //     jQuery.ajax({
            //                     "type": "post",
            //                     "url": 'baseData_checkValue.do',
            //                     "dataType": "json",
            //                     "data": {
            //                         "table": checkTable,
            //                         "theKey": theKey,
            //                         "checkValue": checkValue,
            //                         "theValue": theValue
            //                     },
            //                     "async": true,// false 同步
            //                     "timeout": 5000,
            //                     success: function (result) {
            //                         if (result) {
            //                             if (result.resCode == 1) {
            //                                 obj.combogrid("setValue",
            //                                               result.resValue);
            //                                 obj.combogrid("setText", result.resKey);
            //                                 if (table) {
            //                                     obj.combogrid("grid").datagrid(
            //                                         'reload', {'keyword': ''});
            //                                 } else {
            //                                     var firstSel = $("input[childSelect="
            //                                                      + secondSelect
            //                                                      + "]")[0];
            //                                     loadSecondData($(firstSel), obj);
            //                                 }
            //                             } else {
            //                                 obj.combogrid("clear");
            //                                 //clear hidden value
            //                                 clearHiddenValue(keyId, valueId, codeId);
            //                                 var ids = [valueId, keyId, codeId];
            //                                 validate(ids);
            //                             }
            //                         }
            //                     },
            //                     error: function (XMLHttpRequest, textStatus,
            //                                      errorThrown) {
            //                         //	alert("网络异常，请稍后再试！");
            //                         $.messager.alert('提示', "网络异常，请稍后再试！");
            //                     }
            //                 });
            //     //清除二级下拉框的值
            //     /*var childSelect = obj.attr("childSelect");
            //      if(childSelect) {
            //      $("input[secondSelect="+childSelect+"]").each(function() {
            //      var secondSEL = $(this);
            //      var secondClass = secondSEL.attr("class");
            //      if(secondClass && secondClass.indexOf("combogrid-f")>-1) {
            //
            //      secondSEL.combogrid("clear");
            //      }
            //      });
            //      }*/
            // }
        },
        onChange: function (nv, ov) {
            //alert("onchange...");
            var v = obj.combogrid("getValue");

            if (!v) {
                //clear hidden value
                clearHiddenValue(keyId, valueId, codeId);
            }

            var selected = obj.combogrid('grid').datagrid("getSelected");
            if (selected) {
                setKeyIdAndValuIdForValue(keyId, valueId, codeId, selected[theKey],
                                          selected[theValue], selected[theCode]);
                obj.combogrid("textbox").next().val(selected[theKey]);//由于插件问题，重新设置下拉框显示值
                if (notClearIfNotExist) {
                    $("#" + keyId).attr("value", selected[theKey]);
                }
                validateValueId(valueId, selected[theValue]);
                var selectId = $(this).attr("id");
                hsbmSelect($(this), selected);

                var childSelect = obj.attr("childSelect");
                if (childSelect) {
                    $("input[secondSelect=" + childSelect + "]").each(function () {
                        var secondSEL = $(this);
                        var secondClass = secondSEL.attr("class");
                        if (secondClass && secondClass.indexOf("combogrid-f") > -1) {
                            secondSEL.combogrid("clear");
                            loadSecondData(obj, secondSEL);
                        } else {
                            secondSEL.prev().children().val("");
                            secondSEL.next().val("");
                            secondSEL.val("");
                        }
                    });
                }
            }

            var ids = [valueId, keyId, codeId];
            validate(ids);
        }
    };
    if (typeof(url) === "string") {
        combogridConfig.url = url;
    } else {
        combogridConfig.data = url;
    }
    /* */
    obj.combogrid(combogridConfig);

    if (secondTable && secondSelect) {
        var firstSelect = $("input[childSelect=" + secondSelect + "]")[0];
        if (firstSelect) {
            firstSelect = $(firstSelect);
            loadSecondData(firstSelect, obj);
        }
    }

    obj.combogrid('grid').datagrid({
                                       onSelect: function () {
                                       },
                                       onLoadSuccess: function () {
                                           //默认选中数据第一条
                                           if (obj.combogrid("getText") && obj.combogrid("getValue")
                                               &&
                                               (obj.combogrid("getText") == obj.combogrid(
                                                   "getValue")) &&
                                               obj.combogrid('grid').datagrid("getData").rows[0]) {
                                               obj.combogrid('grid').datagrid('selectRow', 0);
                                           }
                                       }
                                   });

    //设置分页组件
    obj.combogrid('grid').datagrid('getPager').pagination({
                                                              "showRefresh": false,
                                                              "displayMsg": "",
                                                              "showPageList": false
                                                          });
    obj.combogrid("setText", reshowValue);
    if (obj.attr("readonly") == "readonly") {
        isHidenPanel = 1;
    }
    if (!isHidenPanel || isHidenPanel != 1) {
        obj.combogrid("showPanel");
    }

    var theFindInput = obj.next('span').find('input');
    theFindInput.addClass("enterIndex");
    /*
     var userAgent = navigator.userAgent;     //取得浏览器的userAgent字符串
     if ($.browser.mozilla) {
     if(userAgent.indexOf("Firefox")>-1) {//火狐
     theFindInput.bind('keydown', CheckForEnter);
     } else {
     var browser=navigator.appName;
     var b_version=navigator.appVersion;
     var version=b_version.split(";");
     var trim_Version=version[1].replace(/[ ]/g,"");
     if(browser=="Netscape" && trim_Version=="WOW64") {
     theFindInput.bind('keydown', CheckForEnter);
     } else {
     theFindInput.bind('keypress', CheckForEnter);
     }
     }
     } else {
     theFindInput.bind('keydown', CheckForEnter);
     }
     */
    theFindInput.focus();
    theFindInput.bind("mouseover", function () {
        $(this).attr("title", $(this).attr("value"));
    });
}
function commonSelectFocus(obj) {
    focusDemo(obj);
}

function validateValueId(valueId, value) {
    try {
        var selectDom = $("#" + valueId);
        selectDom.val(value);

        $("#myForm").validate().element(selectDom);
    } catch (e) {
        alert(e);
        // TODO: handle exception
    }
}
function validate(validateIds) {
    for (var index = 0; index < validateIds.length; index++) {
        try {
            var selectDom = $("#" + validateIds[index]);
            $("#myForm").validate().element(selectDom);
        } catch (e) {
            // TODO: handle exception
        }
    }
}
var isHsCodeEdit = 0;
function setIsHsCodeEdit(value) {
    isHsCodeEdit = value;

}

function hsbmSelect(selectDom, selectData) {
    if (selectDom.attr("id") == "goodSelect_hsbm" || selectDom.attr("id") == "hggoodsSelect_spbh") {
        if (isHsCodeEdit == 1) {
            setIsHsCodeEdit(0);

            return;
        }
        isSelectCiqFirstRow = 1;

        var ID = selectData["ID"];
        var HSCODE = selectData["HSCODE"];
        var HSNAME = selectData["HSNAME"];
        var BZJFDW = selectData["BZJFDW"];
        var JFLX = selectData["JFLX"];
        var JYJYLB = selectData["JYJYLB"];
        var HGJGTJ = selectData["MONITOR_COND_NEW"];
        var DANGERFLAG = selectData["DANGER_FLAG"];
        if (JYJYLB) {

        } else {
            JYJYLB = "";
        }

        if (HGJGTJ) {

        } else {
            HGJGTJ = "";
        }
        var SPBSDM = selectData["SPBSDM"];
        var DYHSCODE = selectData["DYHSCODE"];
        var UNIT2 = selectData["UNIT2"];

        if ($("#goodSelect_bzldw").attr("id") || selectDom.attr("isHgjy")) { //国检标准量单位和jflx联动.
            clearSelectValue($("#ciqSelect"));
            $("#good_jyjylb").attr("value", JYJYLB);
            $("#good_hgjgtj").attr("value", HGJGTJ);
            $("#good_dangerFlag").combobox("select", DANGERFLAG);
            $("#good_zwmc").attr("value", HSNAME);
            adjustBaoZhuanSuLiangRequred(HSCODE);

            var params = [];
            params.push(JFLX);
            params.push(UNIT2);
            showLinkData("jy_co_jldw", "JYJYDM", BZJFDW, hsbmSetJYJYjldw, params);
        } else {

        }

        if ($("#hggoodsSelect_dyjldw").attr("id")) {//海关第一单位
            $("#hggoods_spmc").attr("value", HSNAME);

            showLinkData("hg_co_jldw", "HGDM", BZJFDW, hsbmSetGJdiyijldw, null);
        }

        //海关和检验检疫的 第二计量单位
        try {
            setHgDejldwRequredClass(UNIT2);
        } catch (e) {
            // TODO: handle exception
        }
        if (UNIT2) {
            showLinkData("hg_co_jldw", "HGDM", UNIT2, hsbmSetHGdiErjldw, params);
        } else {
            $("#hggoods_dejldw").attr("value", "");
            initSelectTextAndValue($("#hggoodsSelect_dejldw"), "", "");
        }

    }
}
function adjustBaoZhuanSuLiangRequred(HSCODE) {
    var requiredClassName = 'goodRequiredClass';
    var bzslId = "good_bzsl";

    var bzzl = "good_bzzl";
    if (HSCODE.indexOf("0001") == 0) {
        clearRequiredClass(bzslId, requiredClassName);
        clearRequiredClass(bzzl, requiredClassName);
    } else {
        addRequiredClass(bzslId, requiredClassName);
        addRequiredClass(bzzl, requiredClassName);
    }
}

function hsbmSetGJdiyijldw(json, params) {
    if (json && json.rows && json.rows[0]) {

    } else {
        return;
    }
    // if (json && json.rows && json.rows[0]) {
    //
    // } else {
    //     return;
    // }
    // var selectData = json.rows[0];
    var selectData = json.rows[0];
    initSelectTextAndValue($("#hggoodsSelect_dyjldw"), selectData.SHOWNAME, selectData.ID);
    $("#hggoods_dyjldw").attr("value", selectData.ID);
    $("#hggoods_dyjldwName").attr("value", selectData.SHOWNAME);

    hsbmFocusHg();
}

function hsbmSetHGdiErjldw(json, params) {
    if (json && json.rows && json.rows[0]) {

    } else {
        return;
    }
    try {
        var selectData = json.rows[0];
        initSelectTextAndValue($("#hggoodsSelect_dejldw"), selectData.SHOWNAME, selectData.ID);
        $("#hggoods_dejldw").attr("value", selectData.ID);
        $("#hggoods_dejldwName").attr("value", selectData.SHOWNAME);
    } catch (e) {
        // TODO: handle exception
    }

    try {
        var JFLX = params[0];
        var unit2 = params[1];
        var selectData = json.rows[0];

        var selectdataDom;
        var dwmcInput;
        var dwIdInput;
        if (JFLX != 2) {//数量单位与标准计量单位相同,则设置的为重量单位
            selectdataDom = $("#good_zldwSelect");
            dwmcInput = $("#good_zldwmc");
            dwIdInput = $("#good_zldw");
        } else if (JFLX == 2) {//重量单位与标准计量单位相同,则设置的为数量单位
            selectdataDom = $("#goodSelect_sldw");
            dwmcInput = $("#good_sldwmc");
            dwIdInput = $("#good_sldw");
        }
        initSelectTextAndValue(selectdataDom, selectData.SHOWNAME, selectData.ID);
        dwIdInput.attr("value", selectData.ID);
        dwmcInput.attr("value", selectData.SHOWNAME);
    } catch (e) {
        // TODO: handle exception

    }

    hsbmFocusHg();
}
var JFLXParam;

function hsbmSetJYJYjldw(json, params) {
    /*initSelectValueS($("#goodSelect_bzldw"),jldwSelectDate["ID"]);
     initSelectValueS($("#hggoodsSelect_dyjldw"),jldwSelectDate["ID"]);*/
    if (json && json.rows && json.rows[0]) {

    } else {
        return;
    }
    var selectData = json.rows[0];
    initSelectTextAndValue($("#goodSelect_bzldw"), selectData.SHOWNAME, selectData.ID);
    $("#good_bzldwmc").attr("value", selectData.SHOWNAME);
    $("#good_bzldw").attr("value", selectData.ID);

    //国检带出 数量单位或者 重量单位 其中之一

    var JFLX = params[0];
    var unit2 = params[1];
    setJyBjslAndBjzlRequredClass(JFLX);
    setJyUnit2RequredClass(unit2, JFLX);

    if (JFLX != 2) {//数量单位与标准计量单位相同
        JFLXParam = "good_bjsl";

        initSelectTextAndValue($("#goodSelect_sldw"), selectData.SHOWNAME, selectData.ID);
        $("#good_sldw").attr("value", selectData.ID);
        $("#good_sldwmc").attr("value", selectData.SHOWNAME);

        if (!unit2 || "" == unit2 || "null" == unit2) {
            clearSelectValue($("#good_zldwSelect"));
            $("#good_zldw").attr("value", "");
            $("#good_zldwmc").attr("value", "");
            $("#good_bjzl").attr("value", "");
        }

    } else if (JFLX == 2) {//重量单位与标准计量单位相同
        //
        JFLXParam = "good_bjzl";
        initSelectTextAndValue($("#good_zldwSelect"), selectData.SHOWNAME, selectData.ID);
        $("#good_zldw").attr("value", selectData.ID);
        $("#good_zldwmc").attr("value", selectData.SHOWNAME);

        if (!unit2 || "" == unit2 || "null" == unit2) {
            clearSelectValue($("#goodSelect_sldw"));
            $("#good_sldw").attr("value", "");
            $("#good_sldwmc").attr("value", "");
            $("#good_bjsl").attr("value", "");
        }
    }

    focusJyAndGjHSCode();

}
function focusJyAndGjHSCode() {
    var hsCode = $("#goodSelect_hsbm");
    if (!hsCode.attr("id")) {
        hsCode = $("#hggoodsSelect_spbh");
    }
    commonSelectFocus(hsCode);
}

function hsbmFocusJy() {
    focusJyHsbm();
}
function hsbmFocusHg() {
    focusHgHsbm();
}

function focusHgGoodName() {
    $("#hggoods_spmc").focus();
}
function focusJyCiq() {
    clearSelectValue($("#ciqSelect"));
    focusDemo($("#ciqSelect"));

}
function focusHgHsbm() {
    focusDemo($("#hggoodsSelect_spbh"));
}
function focusJyHsbm() {
    focusDemo($("#goodSelect_hsbm"));
}
function focusDemo(jqueryObject) {
    try {
        //让光标返回 输入框.
        jqueryObject.next('span').find('input').focus();
    } catch (e) {

    }
}

function initSelectValueS(selectDemo, myValue) {
    selectDemo.combogrid("setValue", myValue);
}

function initSelectTextS(selectDemo, myText) {
    selectDemo.combogrid("setText", myText);
}

function clearSelectValue(selectDemo) {
    try {
        selectDemo.combogrid("clear");
    } catch (e) {
        initByInputObject(selectDemo);
        selectDemo.combogrid("clear");
    }
}

function initSelectTextAndValue(selectDemo, myText, myValue) {
    clearSelectValue(selectDemo);
    initSelectTextAndValueWithoutClear(selectDemo, myText, myValue);
}
function initSelectTextAndValueWithoutClear(selectDemo, myText, myValue) {
    initSelectValueS(selectDemo, myValue);
    initSelectTextS(selectDemo, myText);
}

var isSelectCiqFirstRow = 1;
//二级联动下拉框数据的加载
function loadSecondData(firstDOM, secondDOM, q) {

    var hasInit = secondDOM.attr("hasInit");
    if (hasInit == "0") {
        var theTempValue = secondDOM.combogrid("getValue");
        var theTempText = secondDOM.combogrid("getText");
        secondDOM.combogrid({
                                url: 'baseData_loadSecondData.do'
                            });
        secondDOM.attr("hasInit", "1");
        secondDOM.combogrid("setValue", theTempValue);
        secondDOM.combogrid("setText", theTempText);
    }

    var property = {};
    if (!firstDOM.attr("isInit") || firstDOM.attr("isInit") != "1") {
        property.firstValue = firstDOM.val();
    } else {
        property.firstValue = firstDOM.combogrid("getValue");
    }

    property.firstTable = firstDOM.attr("selectData");
    property.firstTheValue = firstDOM.attr("theValue");
    property.filterValue = secondDOM.attr("filterValue");
    property.filterColumn = secondDOM.attr("filterColumn");
    property.secondTheValue = secondDOM.attr("theValue");
    property.secondTheKey = secondDOM.attr("theKey");
    property.secondTable = secondDOM.attr("seondeData");

    secondDOM.combogrid("grid").datagrid('reload', {
        "firstValue": property.firstValue, "firstTable": property.firstTable,
        "firstTheValue": property.firstTheValue, "filterValue": property.filterValue,
        "filterColumn": property.filterColumn, "secondTheValue": property.secondTheValue,
        "secondTheKey": property.secondTheKey, "secondTable": property.secondTable,
        "keyword": q
    });

    secondDOM.combogrid('grid').datagrid({
                                             onSelect: function () {
                                             },
                                             onLoadSuccess: function () {
                                                 /**/
                                                 //默认选中数据第一条
                                                 if (secondDOM.combogrid("getText")
                                                     && secondDOM.combogrid("getValue") &&
                                                     (secondDOM.combogrid("getText")
                                                      == secondDOM.combogrid("getValue")) &&
                                                     secondDOM.combogrid('grid').datagrid(
                                                         "getData").rows[0]) {
                                                     secondDOM.combogrid('grid').datagrid(
                                                         'selectRow', 0);
                                                 }

                                                 if (secondDOM.attr("id") == "ciqSelect"
                                                     && isSelectCiqFirstRow == 1
                                                     && secondDOM.combogrid('grid').datagrid(
                                                         "getData").rows[0]) {

                                                     //alert(secondDOM.attr("id")+":secondDom:"+JSON.stringify(secondDOM.combogrid('grid').datagrid("getData").rows[0]));
                                                     var firstData = secondDOM.combogrid(
                                                         'grid').datagrid("getData").rows[0];
                                                     /*firstData.SHOWNAME;
                                                      firstData.ID;
                                                      firstData.STATNAME;*/
                                                     initSelectTextAndValue(secondDOM,
                                                                            firstData.SHOWNAME,
                                                                            firstData.ID);
                                                 }
                                             }
                                         });

    //设置分页组件
    secondDOM.combogrid('grid').datagrid('getPager').pagination({
                                                                    "showRefresh": false,
                                                                    "displayMsg": "",
                                                                    "showPageList": false
                                                                });

    secondDOM.combogrid('grid').datagrid('getPager').pagination("select", 1);
}

function showLinkData(linkTable, linkKey, linkKeyVal, callBackFunction_Name, params) {
    jQuery.ajax({
                    "type": "post",
                    "url": '/order-dropdown/baseData_linkData',
                    "dataType": "json",
                    "data": {"linkTable": linkTable, "linkKey": linkKey, "linkKeyVal": linkKeyVal},
                    "async": true,// false 同步
                    "timeout": 5000,
                    success: function (result) {
                        //do something...
                        //alert("json_result"+JSON.stringify(result));
                        callBackFunction_Name(result, params);

                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //	alert("网络异常，请稍后再试！");
                        $.messager.alert('提示', "网络异常，请稍后再试！");
                    }
                });
}
function setJyjyCaculate(hsCode) {
    showLinkData("co_sphsbm", "HSCODE", hsCode, setJyjyCaculateCallBack, null);
}
function setJyjyCaculateCallBack(json, params) {
    if (json && json.rows && json.rows[0]) {

    } else {
        return;
    }
    var selectData = json.rows[0];
    var JFLX = selectData.JFLX + "";
    var unit2Code = selectData.UNIT2 + "";
    setJyBjslAndBjzlRequredClass(JFLX);
    if ("2" != JFLX) {
        JFLXParam = "good_bjsl";
    } else if ("2" == JFLX) {
        JFLXParam = "good_bjzl";
    }

    try {
        setJyUnit2RequredClass(unit2Code, JFLX);
    } catch (e) {
        // TODO: handle exception
    }

}

function setHgDejldwRequired(hsCode) {
    showLinkData("co_sphsbm", "HSCODE", hsCode, setHgDejldwRequiredCallBack, null);
}

function setHgDejldwRequiredCallBack(json, params) {

    if (json && json.rows && json.rows[0]) {

    } else {
        return;
    }
    var selectData = json.rows[0];
    var unit2Code = selectData.UNIT2 + "";
    var JFLX = selectData.JFLX;
    try {
        setHgDejldwRequredClass(unit2Code);
    } catch (e) {
        // TODO: handle exception

    }

}

var requiredShowHtml = "<span class=\"mustRemark\">*</span>";

var hgRequriedClass = "hgGoodRequired";
function setGoodRequiredName() {
    //判断是否是关检联合界面,是的话, 校验class 为 = goodRequiredClass,用于程序设置第二计量单位的必填项
    if ($("#good_bjsl").attr("id") == "good_bjsl") {
        hgRequriedClass = "goodRequiredClass";
    }
}
function setHgDejldwRequredClass(unit2Code) {
    var inputIds = ["hggoods_desl", "hggoods_dejldw"];//需要设置的
    setGoodInputRequredClass(unit2Code, inputIds);
}
function setJyBjslAndBjzlRequredClass(jflx) {
    var slFlag = "";
    var zlFlag = "";
    if (jflx != 2) {//数量单位与标准计量单位相同
        slFlag = "1";
    } else if (jflx == 2) {//重量单位与标准计量单位相同
        zlFlag = "1";
    }
    setJyBjslRequredClass(slFlag);
    setJyBjzlRequredClass(zlFlag);
}

function setJyUnit2RequredClass(unit2Code, jflx) {
    if (unit2Code && "" != unit2Code && "null" != unit2Code) {
        if (jflx != 2) {//数量单位与标准计量单位相同,则重量单位也必填
            setJyBjzlRequredClass(1);
        } else if (jflx == 2) {//重量单位与标准计量单位相同,则数量单位也必填
            setJyBjslRequredClass(1);
        }
    }
}

function clearJyBjslAndBjzlRequredClass() {
    setJyBjslAndBjzlRequredClass(3);
}
function setJyBjslRequredClass(code) {
    var inputIds = ["good_bjsl", "good_sldw"];//需要设置的
    setGoodInputRequredClass(code, inputIds);
}
function setJyBjzlRequredClass(code) {
    var inputIds = ["good_bjzl", "good_zldw"];//需要设置的
    setGoodInputRequredClass(code, inputIds);
}
function setGoodInputRequredClass(unit2Code, inputIds) {
    setGoodRequiredName();
    if (unit2Code && "" != unit2Code && "null" != unit2Code) {
        for (var index = 0; index < inputIds.length; index++) {
            addRequiredClass(inputIds[index], hgRequriedClass);
        }
    } else {
        for (var index = 0; index < inputIds.length; index++) {
            clearRequiredClass(inputIds[index], hgRequriedClass);
        }
    }
}

function addRequiredClass(inputId, className) {

    $("#" + inputId).addClass(className);
    var preDeom = $("#" + inputId).parent().prev();
    //preDeom.css("background-color","rgb(254, 219, 196)");
    var html = preDeom.html();
    if (html.indexOf("*") == -1) {
        html = requiredShowHtml + html;
    }
    preDeom.html(html);

}

function clearRequiredClass(inputId, className) {
    $("#" + inputId).removeClass(className);
    var preDeom = $("#" + inputId).parent().prev();
    preDeom.css("background-color", "");
    /*var html = preDeom.html().replace(requiredShowHtml,"");
     preDeom.html(html);*/
    preDeom.find("span:contains(*)").remove();
}

function clearHgDejldwRequredClass() {
    setHgDejldwRequredClass("");
}

function setKeyIdAndValuIdForValue(keyId, valueId, codeId, keyValue, valueValue, codeValue) {
    if (keyId != null) {
        $("#" + keyId).val(keyValue);

    }
    if (valueId != null) {
        $("#" + valueId).val(valueValue);

    }
    if (codeId != null) {
        $("#" + codeId).val(codeValue);
    }
}

function clearHiddenValue(keyId, valueId, codeId) {
    if (keyId != null) {
        $("#" + keyId).val("");

    }
    if (valueId != null) {
        $("#" + valueId).val("");

    }
    if (codeId != null) {
        $("#" + codeId).val("");
    }
}
//数据的过滤方法？？？
function loadDataFilter(data) {
    if (!data) {
        var tempData = {
            "total": 0,
            "rows": []
        };
        return tempData;
    }
    if (typeof data.length == 'number'
        && typeof data.splice == 'function') {   // 判断数据是否是数组
        data = {
            "total": data.length,
            "rows": data
        };
    }
    return data;
}
